//
//  CMainPageCtrl.h
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-7.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
//#import <MapKit/MKMapView.h>
//#import <MapKit/MKAnnotation.h>
//#import <Mapkit/MKPinAnnotationView.h>
//#import <Mapkit/MKUserLocation.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import "CRootCtrlManager.h"
#import "CItemPreView.h"
#import "CTabView.h"
#import "CShareView.h"
#import "CDisCellView.h"
#import "CProduct.h"
#import "CLike.h"
#import "CCommentary.h"
#import "CUIViewEx.h"
#import "CDownLoadManager.h"
#import "CCondition.h"
#import "AppConfig.h"
#import "CUser.h"
#import "CDrawerView.h"
#import "CComEditView.h"
#import "CNoticeView.h"
#import "CPuberInfoView.h"
#import "CLocator.h"
#import "CTopBarView.h"
#import "CMapViewEx.h"
#import "CWaterFall.h"

@class CDrawerView;
@class CRootCtrlManager;
@class CDataStore;
@class CUser;
@class AppConfig;
@class CPuberInfoView;
@class CMapViewEx;
@class CItemPreView;
@class CSearchView;
@class CWaterFall;

@protocol MapViewDelegate;
@protocol ItemPreViewDelegate;
@protocol SearchViewDelegate;
@protocol ComEditDelegate;
@protocol WaterFallDelegate;
//=================================================================================================================================

#define TABBAR_HEIGHT   116
#define PRODUCT_TOTAL   100

//=================================================================================================================================

@interface CSearchItem : UIView

@property (nonatomic, assign) UILabel       *m_Titel;
@property (nonatomic, assign) UIImageView   *m_More;
@property (nonatomic, assign) id            m_Target;
@property (nonatomic, assign) SEL           m_Action;

-(id)initWithFrame:(CGRect)frame Title:(NSString*)titel Tag:(int)tag;

@end

//=================================================================================================================================

@interface CMainPageCtrl : UIViewController<GalleryDelegate, ItemPreViewDelegate, NetWorkRequestDelegate, ShareViewDelegate, ComEditDelegate, SinaWeiboDelegate, QQWeiboDelegate, RenRenDelegate, TabViewDelegate, UIScrollViewDelegate, ProductDelegate, MFMailComposeViewControllerDelegate, TopBarDelegate, MapViewDelegate, UIAlertViewDelegate, UIAccelerometerDelegate, SearchViewDelegate, UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource, WaterFallDelegate>

@property (nonatomic, assign) IBOutlet UIImageView       *m_Bg;

//topbar
@property (nonatomic, assign) CTopBarView       *m_TopBarView;
@property (nonatomic, assign) UIImageView       *m_TopLog;
@property (nonatomic, assign) UIButton          *m_TopSearchBtn;
@property (nonatomic, assign) UIButton          *m_BackBtn;
@property (nonatomic, assign) UIButton          *m_TopRetBtn;
@property (nonatomic, assign) UIButton          *m_TopWrite;
@property (nonatomic, assign) UIButton          *m_TopOption;
@property (nonatomic, assign) UIButton          *m_TopLocation;
@property (nonatomic, assign) UIView            *m_SearchPanel;

@property (nonatomic, assign) CSearchView       *m_SearchView;
@property (nonatomic, assign) UIButton          *m_SearchCancel;
@property (nonatomic, assign) UIImageView       *m_SearchCover;
@property (nonatomic, assign) UIScrollView      *m_SearchPdtPanel;
@property (nonatomic, assign) UITableView       *m_SearchPdtTable;
@property (nonatomic, assign) UIScrollView      *m_SearchResPanel;
@property (nonatomic, assign) UITableView       *m_SearchResTable;
@property (nonatomic, retain) CTask             *m_SearchTask;
@property (nonatomic, assign) UIView            *m_SearchFallPanel;
@property (nonatomic, assign) UILabel           *m_SearchResName;
@property (nonatomic, assign) CWaterFall        *m_SearchFall;
@property (nonatomic, assign) NSMutableArray    *m_SearchPdtsRets;
@property (nonatomic, assign) CAscCounter       *m_SearchPdtNetCnt;
@property (nonatomic, assign) NSMutableArray    *m_SearchResRets;
@property (nonatomic, assign) CAscCounter       *m_SearchResNetCnt;
@property (nonatomic, assign) NSMutableArray    *m_SearchPdtRes;
@property (nonatomic, assign) CAscCounter       *m_SearchPdtResCnt;
@property (nonatomic, assign) BOOL              m_bIsSearchRes;
@property (nonatomic, retain) NSString          *m_SearchValue;

//大图放大
@property (nonatomic, assign)           UIView  *m_BigImageView;
@property (nonatomic, assign)           UIView  *m_BgView;
@property (nonatomic, assign)      UIImageView  *m_BigImage;
@property (nonatomic, assign)           BOOL    m_bIsBigImageShow;

@property (nonatomic, assign)           NSMutableArray        *m_Datas;
@property (nonatomic, assign)           UILabel               *m_Address;
@property (nonatomic, assign)  IBOutlet CItemPreView          *m_ItemPreview;
@property (nonatomic, assign)           BOOL                  m_bIsGalleryMoved;
//tabview
@property (nonatomic, assign)           CTabView              *m_TabView; 
@property (nonatomic, assign)           int                   m_nTabPosition;

@property (nonatomic, assign)  IBOutlet UIView  *m_RightPanel;

//root
@property (nonatomic, assign) BOOL              m_bIsHidden;
@property (nonatomic, assign) UIImage           *m_DfIcon;
@property (nonatomic, assign) NSData            *m_DfData;
@property (nonatomic, assign) BOOL              m_bIsUpdate;        //页面内容刷新
@property (nonatomic, assign) UCommand          m_Command;
@property (nonatomic, assign) int               m_nModel;           //0常规模式，1地图模式

//bottombar
@property (nonatomic, assign) IBOutlet UIView   *m_BottomBar;
@property (nonatomic, assign) IBOutlet UILabel  *m_Eatlb;
@property (nonatomic, assign) IBOutlet UILabel  *m_Wantlb;
@property (nonatomic, assign) IBOutlet UILabel  *m_Nicelb;

//信息
@property (nonatomic, assign) IBOutlet  UIView  *m_FoodInfoPanel;
@property (nonatomic, assign) IBOutlet  UILabel *m_FoodName;
@property (nonatomic, assign) IBOutlet  UILabel *m_FoodRes;
@property (nonatomic, assign) IBOutlet  UILabel *m_Publisher;
@property (nonatomic, assign) IBOutlet  UIButton*m_PinglunBtn;
@property (nonatomic, assign) IBOutlet  UILabel *m_UserNick;
@property (nonatomic, assign) IBOutlet  UILabel *m_PrdctSum;
@property (nonatomic, assign) IBOutlet  UIButton*m_ResBtn;
@property (nonatomic, assign) IBOutlet  UIButton*m_PuberBtn;
@property (nonatomic, assign)     CPuberInfoView*m_PubInfoView;

//topbar
@property (nonatomic, assign) IBOutlet    UIView  *m_TopBar;
@property (nonatomic, assign) IBOutlet    UIButton*m_ShareBtn;
@property (nonatomic, assign) IBOutlet    UIButton*m_MapBtn;
@property (nonatomic, assign) IBOutlet    UIButton*m_FavoBtn;
//discssion
//@property (nonatomic, assign) NSThread        *m_ComsThread;
@property (nonatomic, assign) NSMutableArray  *m_DisDatas;
//评价
@property (nonatomic, assign) IBOutlet  UILabel     *m_NoComslb;
@property (nonatomic, assign) IBOutlet  UIActivityIndicatorView *m_ComsIndicator;
@property (nonatomic, assign) IBOutlet  UITableView *m_TableView;
//抽屉
@property (nonatomic, assign) IBOutlet  CDrawerView *m_DrawerView;
@property (nonatomic, assign)           CGPoint     m_lsidepoint;
@property (nonatomic, assign)           BOOL        m_IslsideShow;
//地图
@property (nonatomic, assign) IBOutlet  UIView      *m_MapPanel; 
@property (nonatomic, assign)           CMapViewEx  *m_Map;
@property (nonatomic, assign)      UIImageView      *m_Anchor;
@property (nonatomic, assign) IBOutlet  UIButton    *m_MapBack;
@property (nonatomic, assign) IBOutlet  UIButton    *m_Location;
@property (nonatomic, retain)           CTask       *m_Task;
@property (nonatomic, assign) IBOutlet  UILabel     *m_MapAddr;
//美食
@property (nonatomic, assign) BOOL         m_bIsLoading;
@property (nonatomic, assign) CAscCounter  *m_NativeDBCnt;
@property (nonatomic, assign) CProduct     *m_CurPrdct;
//search
@property (nonatomic, assign) BOOL         m_bSearchSwitch;
@property (nonatomic, assign) BOOL         m_bIsVagueSearch;
//network
@property (nonatomic, assign) CAscCounter  *m_NetCnt;
@property (nonatomic, assign) CAddrInfo    *m_RqstAddr;

//shake
@property (nonatomic, assign) NSInteger   m_nShakeCnt;
@property (nonatomic, assign) NSDate      *m_ShakeStart;
@property (nonatomic, assign) BOOL        m_bIsShake;

//share
@property (nonatomic, assign) UIActionSheet *m_Sheet;

//fresh
@property (nonatomic, assign) BOOL        m_bIsFresh;

+(CMainPageCtrl*)DefaultMainPageCtrl;
+(void)DestroyMainPageCtrl;

-(void)InitMainPageView:(BOOL)isload;
-(void)ResetMainView;

//topbarview
-(void)SetUpTopBar;
-(void)OnTopBarDown:(UIButton*)sender;
-(void)SetUpSearchBar;
-(void)OnSearchBackDown:(UIButton*)sender;
-(void)ShowSearchView;
-(void)SearchViewBecomeFirstResponse;
-(void)HiddeSearchView;
-(void)DidSearchViewHidden;
-(void)ShowSearchFall;
-(void)HiddenSearchFall;
-(void)DidSearchFallHidden;
-(void)DidSearchFallShown;
-(void)OnSearchCancleDown:(UIButton*)sender;
-(void)GetProductsOfRes:(NSString*)name;
-(void)DidReceivePdtOfRes:(NSArray*)data;
-(void)DidReceiveProducts:(NSArray*)data;
-(void)DidReceiveRestaurants:(NSArray*)data;
-(void)DidSearchPdtClicked:(CSearchItem*)sender;
-(void)DidSearchResClicked:(CSearchItem*)sender;

//self
-(void)ShowHomePageCtrl;
-(void)HiddenHomePageCtrl;

//position
-(NSString*)GetUserPosition;

//favorite
-(void)DidFavoriteClicked;

//topbar
-(void)OnTopBarBtnDown:(int)index;
-(void)FavoriteAction;
-(void)ShareAction;
-(void)OnShareSelected:(int)buttonIndex;
-(void)DidEmailShare;
-(void)DisplayComposerSheet;
-(void)ShowTopBar:(BOOL)isShow;
//bottombar
-(void)OnBottomBarBtnDown:(int)index;
-(void)ShowBottomBar:(BOOL)isShow;

-(void)CheckPdtIsFavorite:(CPreItem*)item;

//information
-(IBAction)OnResBtnDown:(UIButton*)sender;
-(IBAction)OnPuberBtnDown:(UIButton*)sender;
-(void)DidPuberInfoViewShow;
-(void)DidRetBtnDown;

//bigimageview
-(void)SetBigImageViewImage:(CProduct*)pdct;
-(void)ShowBigImageView:(UIImage*)image;
-(void)HiddenBigImageView;
-(void)DidBigImageHidden;
-(void)DidBigImageViewShow;
-(void)DidBigImageShown;
-(void)DidBigImageViewHidden;

//地图
-(void)InitMapData;
-(void)ShowMapView;
-(void)DidShowMapView;
-(IBAction)OnMapViewBtnDown:(UIButton*)sender;
-(void)SetLocations:(NSArray*)locations;
//定位自己的位置
-(void)LocationMsgListener:(NSNotification*)notification;

//美食
-(void)InitTabViewWithTabFocus:(int)focus;
-(void)InitItemPreView;
-(void)AddProductsToTabView:(NSArray*)products;
-(void)SetProductInfo:(int)index;
-(void)SetButtomInfo:(CProduct*)product;
-(void)IsDidProductFavorited:(id)product;
-(void)SetDidFavoritedFlag:(id)product;
-(void)CancelFavorite;

//美食评论
-(void)CommentariesWorker:(id)object;
-(void)ShowComsIndicator;
-(void)HiddenComsIndicator;
-(IBAction)OnCommitDis:(UIButton*)sender;
-(void)DidComEditViewCommit:(id)object;

//search
//-(void)InitSearchView;

//shake
-(void)FreshMianPage:(BOOL)isshowindicator;
//best
-(void)FreshBestAction;
//nearest
-(void)FreshNearestAction;
//newest
-(void)FreshNewestAction;

//network glob
-(void)RequestError:(NSNotification*)mes;
-(void)UpDateUIWhenRequestError:(id)object;
-(void)RequestTimeOut:(NSNotification*)mes;
-(void)UpdateUIWhenRequestTimeout:(id)object;

//network
//get more data
-(void)GetMoreDatas;
-(void)CommitGetProducts:(NSString*)condition Action:(NSString*)action Code:(int)code Offset:(int)offset Limit:(int)limit Object:(id)object;
-(void)DidReceiveProductsFromSvr:(NSDictionary*)data Info:(id)info;
//best
-(void)CommitBestRequest:(int)offset Limit:(int)limit Action:(NSString*)action Object:(id)object;
-(void)DidReceiveBestDataFromSvr:(NSArray*)products;
//nearest
-(void)CommitNearestRequest:(int)offset Limit:(int)limit Action:(NSString*)action Object:(id)object;
-(void)DidReceiveNearestDataFromSvr:(NSArray*)products;
//newest
-(void)CommitNewestRequest:(int)offset Limit:(int)limit Action:(NSString*)action Object:(id)object;
-(void)DidReceiveNewestDataFromSvr:(NSArray*)products;
//search
-(void)CommitSearchRequest:(int)offset Limit:(int)limit Action:(NSString*)action Object:(id)object;
//-(void)DidReceiveSearchDataFromSvr:(NSArray*)products;
-(void)DidReceiveSearchDataFromSvr:(NSDictionary*)products;
//upload
-(void)CommitMyUploadRequest:(int)offset Limit:(int)limit Action:(NSString*)action Object:(id)object;
-(void)DidReceiveMyUploadDataFromSvr:(NSArray*)products;
//favorite
-(void)CommitMyFavoriteRequest:(int)offset Limit:(int)limit Action:(NSString*)action Object:(id)object;
-(void)DidReceiveMyFavoriteDataFromSvr:(NSArray*)products;
//向服务器提交收藏
-(void)CommitFavorite:(NSString*)paid;
-(void)DidReceiveFavorteNotification:(NSNotification*)nofification;
//tab改变时，定位监听
-(void)TabChangedLoctionListener:(NSNotification*)notification;
//tabselected
-(NSArray*)GetProductsFromDB:(NSString*)condition OpIndex:(int)opindex;
-(void)GetProductsFromServer:(int)index IsInit:(BOOL)binit Object:(id)object;
//upload
-(void)TabUploadAction;
-(NSArray*)GetNativeUpload:(NSString*)condition;
//favorite
-(void)TabFavoriteAction;
-(NSArray*)GetNativeFavorite:(NSString*)condition;
//newest
-(void)TabNewestAction;
-(NSArray*)GetNativeNewest:(NSString*)condition;
//best
-(void)TabBestAction;
-(NSArray*)GetNativeBest:(NSString*)condition;
//nearest
-(void)TabNearestAction;
-(NSArray*)GetNativeNearest:(NSString*)condition;
//search
-(void)TabSearchAction:(int)value;
-(NSArray*)GetNativeSearch:(NSString*)condition;

@end
